//商品列表
var app = getApp(); //全局APP

Page({
	//页面的初始数据
	data: {
		plan_class_id: 0,
		listData: [],
	},

	//加载执行
	onLoad: function(options) {
		var plan_class_id = options.plan_class_id;
		this.setData({
			plan_class_id: plan_class_id
		});
	},
	
	//加载执行
	onShow: function() {
		this.getBookAplyDetail();
	},
	
	getBookAplyDetail: function() {
		var page = this;
		var data = {
			plan_class_id: page.data.plan_class_id
		};
		
		// 获取班级
		app.api.getBookAplyDetail(data, function(res) {
			if (res.status) {
				var tmp_data = [];
				
				for (var i = 0; i < res.data.length; i++) {
					if(res.data[i].sdzt == '0') {
						res.data[i].sdzt = false;
					} else {
						res.data[i].sdzt = true;
					} 
				}
				
				page.setData({
					listData: res.data
				});
			} else {
				//报错了
				app.common.errorToBack(res.msg, 0);
				page.setData({
					listData: []
				});
			}
		});
	},
	
	lock: function(e) {
		var page = this;
		var xh = e.currentTarget.dataset.xh;
		var data = {
			xh: xh
		};
		
		// 锁定
		app.api.studentlock(data, function(res) {
			if (res.status) {
				var listData = page.data.listData;
				
				for (var i = 0; i < listData.length; i++) {
					if (listData[i].xh == xh) {
						listData[i].sdzt = true;
					}
				}
				
				page.setData({
					listData: listData
				});
			}
			
			app.common.errorToBack(res.msg, 0);
		});
	},
	
	unlock: function(e) {
		var page = this;
		var xh = e.currentTarget.dataset.xh;
		var data = {
			xh: xh
		};
		
		// 解锁
		app.api.studentunlock(data, function(res) {
			if (res.status) {
				var listData = page.data.listData;
				
				for (var i = 0; i < listData.length; i++) {
					if (listData[i].xh == xh) {
						listData[i].sdzt = false;
					}
				}
				
				page.setData({
					listData: listData
				});
			}
			
			app.common.errorToBack(res.msg, 0);
		});
	},
});
